//表单校验
$(".username_msg").text("");
$(".password_msg").text("");
$(".password2_msg").text("");
$("#username").blur(function() {
	var username1 = $("#username").val().trim();
	if (username1 == null || username1 == "") {
		$(".username_msg").text("用户名不能为空");
	}
});
$("#password").blur(function() {
	var password = $("#password").val().trim();
	if (password == null || password == "") {
		$(".password_msg").text("密码不能为空");
	}
});
$("#password2").blur(function() {
	var password2 = $("#password2").val().trim();
	if (password2 == null || password2 == "") {
		$(".password2_msg").text("确认密码不能为空");
	}
});

var password1 = $("#password1").val();
var password2 = $("#password2").val();
$("#create_btn")
		.click(
				function() {
					var canCreate = true;
					$(".username_msg").text("");
					$(".password_msg").text("");
					$(".password2_msg").text("");
					var username1 = $("#username").val().trim();
					if (username1 == null || username1 == "") {
						$(".username_msg").text("用户名不能为空");
						canCreate = false;
					}
					var password = $("#password").val().trim();
					if (password == null || password == "") {
						$(".password_msg").text("密码不能为空");
						canCreate = false;
					}
					var password2 = $("#password2").val().trim();
					if (password2 == null || password2 == "") {
						$(".password2_msg").text("确认密码不能为空");
						canCreate = false;
					}
					if (password2 != password) {
						$(".password2_msg").text("确认密码与不一致");
						canCreate = false;
					}
					if (canCreate) {
						$
								.ajax({
									url : "http://localhost:8080/ciic-vote/user/createUser.do",
									type : "post",
									data : $("#create_user_form").serialize(),
									dataType : "json",
									success : function(result) {
										if (result.status == 0) {
											alert("创建成功");
											window.location.href = "findAll.html";
										} else if (result.status == 1) {
											$(".msg")
													.html(
															"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
																	+ "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
																	+ "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
																	+ "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
																	+ "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
																	+ "用户名已存在，请输入新的用户名！");
										}
									}
								});
					}
				});